package org.example.fancystudy.interrupt;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * @author chaigq
 * @version 1.0
 * @date 2022/11/10 11:44
 */
public class InterruptDemo2 {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            while (true){
                if(Thread.interrupted()){
                    System.out.println(Thread.currentThread().getName() + " isInterrupted()被修改为true，程序停止");
                    break;
                }
                System.out.println(Thread.currentThread().getName() + "正在执行");
            }
        }, "thread");
        thread.start();


        try {
            TimeUnit.SECONDS.sleep(2);
        }catch (InterruptedException e){
            e.printStackTrace();
        }

        new Thread(() -> {
            thread.interrupt();
        },"thread2").start();
    }
}
